package com.jmu.medicineknows.controller;

import com.jmu.medicineknows.dto.UserListDto;
import com.jmu.medicineknows.entity.Result;
import com.jmu.medicineknows.entity.User;
import com.jmu.medicineknows.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author Administrator
 */
@Slf4j
@RestController
@Api(tags = "用户接口")
@RequestMapping("/permission")
public class UserController {

    @Autowired
    public UserService userService;

    @ApiOperation("登录接口")
    @PostMapping("/LoginInfo")
    public Result login(@RequestBody User user){
        return userService.login(user);
    }

    @ApiOperation("注册接口")
    @PostMapping("/Register")
    public Result register(@RequestBody User user){
        return userService.register(user);
    }

    @ApiOperation("图片上传接口")
    @RequestMapping("/upload")
    public Result uploadAvatar(MultipartFile file){
        return userService.upload(file);
    }

    @ApiOperation("更新用户")
    @RequestMapping("/update")
    public Result updateUser(@RequestBody User user){
        return userService.update(user);
    }

    @ApiOperation("菜单接口")
    @GetMapping("/getMenuList")
    public Result navData(){
        return userService.navData();
    }

    @ApiOperation("注销")
    @GetMapping("/logout")
    public Result logout(){
        return userService.logout();
    }

    @ApiOperation("DAU接口")
    @GetMapping("/dau")
    public Result getDau(){
        return userService.getDau();
    }
    @ApiOperation("通过日期获取DAU")
    @GetMapping("/dauByDate/{date}")
    public Result getDauByDate(@PathVariable("date") String date){
        return userService.getDauByDate(date);
    }

    @ApiOperation("获取用户总数")
    @GetMapping("/userCount")
    public Result userCount(){
        return userService.userCount();
    }

    @ApiOperation("获取PV接口")
    @GetMapping("/pvCount")
    public Result pvCount(){
        return userService.pvCount();
    }

    @ApiOperation("绑定社保卡")
    @PostMapping("/binding")
    public Result binding(@RequestBody User user){
        return userService.binding(user);
    }

    @ApiOperation("查询当前社保卡号是否已经绑定到用户上")
    @PostMapping("/checkBinding")
    public Result checkBinding(@RequestBody User user){
        System.out.println(user);
        return userService.checkBinding(user);
    }

    @ApiOperation("获取用户列表")
    @PostMapping("/userList")
    public Result userList(@RequestBody UserListDto dto){
        return userService.userList(dto);
    }

    @ApiOperation("删除用户")
    @GetMapping("/deleteUser/{id}")
    public Result delete(@PathVariable("id") Long id){
        return userService.delete(id);
    }
}
